<template>
  <div class="add-address">
    <van-nav-bar
      title="新增地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="address">
      <div class="name total">
        <span>姓名</span
        ><input v-model="address.name" type="text" placeholder="姓名" />
      </div>

      <div class="phone total">
        <span>手机号</span
        ><input v-model="address.phone" type="text" placeholder="手机号" />
      </div>
      <div class="ads total">
        <span>收货地址</span
        ><input v-model="address.ads" type="text" placeholder="地址" />
      </div>
    </div>
    <div class="tr" @click="add">保存</div>
  </div>
</template>

<script>
import { address_add } from "../axios/api";
import { Toast } from "vant";
export default {
  data() {
    return {
      address: {
        name: "",
        phone: "",
        ads: "",
      },
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    add() {
      address_add({
        userid: JSON.parse(localStorage.getItem('userinfo')).id,
        address: this.address.ads,
        phone: this.address.phone,
        name: this.address.name,
      }).then((res) => {
          console.log(res);
        this.$store.addressList = res.data.list;
        Toast.success("保存成功！")
          this.$router.go(-1)
      });
    },
  },
};
</script>
<style scoped lang="scss">
.address {
  display: flex;
  flex-direction: column;
  span {
    font-size: 18px;
    font-weight: 500;
    width: 100px;
  }
  .total {
    display: flex;
    margin: 15px;
    input {
      display: block;
      height: 30px;
      border: none;
      outline: none;
      padding: 0 30px;
    }
  }
}
.tr {
  text-align: center;
  margin: 30px;
  font-size: 20px;
  font-weight: 600;
  box-sizing: border-box;
  padding: 10px 50px;
  border-radius: 10px;
  background-color: deepskyblue;
}
</style>